package asteroids.model.programs.expression;

import java.util.ArrayList;

import asteroids.model.programs.expression.E;
import asteroids.model.programs.type.*;
import asteroids.model.*;

public abstract class Getter extends DoubleExpression {
	
	private E e;
	
	public Getter(int line, int column, E e) {
		super(line, column);
		this.e = e;
	}

	@Override
	public abstract DoubleType getValue();

	public E getExpression(){
		return e;
	}
	
	@Override
	public ArrayList<VariableExpression> getVariables(){
		ArrayList<VariableExpression> list = new ArrayList<VariableExpression>();
		if(VariableExpression.class.isAssignableFrom(e.getClass()))
			list.add((VariableExpression) e);
		return list;
	}
	
	public String typecheck(){
		String eTypeCheck = getExpression().typecheck();
		if(!eTypeCheck.equals(""))
			return eTypeCheck;
		if(getExpression().getValue() == null)		
			return "Typecast error at line " + getLine() + ", column " + getColumn() + ".\n";
		if(getExpression().getValue().getClass() == Entity.class || getExpression().getValue().getClass() == ShipType.class)
			return "";
		return "Typecast error at line " + getLine() + ", column " + getColumn() + ".\n";
	}
}
